// 该ts文件用于定义并暴露SPU相关的接口
import request from "@/utils/request";
import type { getSpuListResponseData } from "./type";
enum API {
  // 获取SPU列表的接口地址
  SPULIST_URL = "/admin/product/",
  // 获取SPU的商品列表的接口地址
  TRADEMARK_LIST = "/admin/product/baseTrademark/getTrademarkList",
  // 获取SPU图片的接口地址
  SPUIMAGELIST_URL = "/admin/product/spuImageList/",
  // 获取SPU销售属性的接口地址
  BASESALEATTRLIST_URL = "/admin/product/baseSaleAttrList",
  // 获取某一个SPU已有的全部销售属性的接口地址
  HASALLSALEATTR_URL = "/admin/product/spuSaleAttrList/",
  // 添加spu的接口地址
  SAVESPUINFO_URL = "/admin/product/saveSpuInfo",
  //修改spu的接口地址
  UPDATESPUINFO_URL = "/admin/product/updateSpuInfo",
  // 添加sku的接口地址
  SAVESKU_URL = "/admin/product/saveSkuInfo",
  // 获取sku列表的接口地址
  SKULIST_URL = "/admin/product/findBySpuId/",
  // 删除sku的接口地址
  DELETESPU_URL = "/admin/product/deleteSpu/",
}
// 获取SPU列表的接口
export const reqGetSpuList = (
  page: number,
  limit: number,
  category3Id: number | string
) =>
  request.get<any, getSpuListResponseData>(
    API.SPULIST_URL + `${page}/${limit}?category3Id=${category3Id}`
  );
// 获取SPU的商品列表的接口
export const reqGetTrademarkList = () =>
  request.get<any, any>(API.TRADEMARK_LIST);
// 获取SPU图片的接口
export const reqGetSpuImageList = (spuId: number) =>
  request.get<any, any>(API.SPUIMAGELIST_URL + spuId);
// 获取SPU的全部销售属性的接口
export const reqGetBaseSaleAttrList = () =>
  request.get<any, any>(API.BASESALEATTRLIST_URL);
// 获取某一个SPU已有的全部销售属性的接口
export const reqGetHasSaleAttr = (spuId: number) =>
  request.get<any, any>(API.HASALLSALEATTR_URL + spuId);
// 添加或修改spu的接口
export const reqSaveOrUpdateSpuInfo = (data: any) => {
  if (data.id) {
    return request.post<any, any>(API.UPDATESPUINFO_URL, data);
  } else {
    return request.post<any, any>(API.SAVESPUINFO_URL, data);
  }
};
// 添加sku的接口
export const reqSaveSku = (data: any) =>
  request.post<any, any>(API.SAVESKU_URL, data);
// 获取sku列表的接口
export const reqGetSkuList = (spuId: number) =>
  request.get<any, any>(API.SKULIST_URL + spuId);
// 删除sku的接口
export const deleteSpu = (skuId: number) =>
  request.delete(API.DELETESPU_URL + skuId);
